<template>
	<view>
		<view class="topBox">
			<view class="topBoxbg">
				<image src="../../static/usercenter/jlbg.png"></image>
			</view>
			<view class="timeselect">
				<picker mode="date" :value="date" :start="startDate" :end="endDate" @change="bindDateChange">
					<view class="uni-input">{{date}}</view>
				</picker>
				<image class="select-icon" src="../../static/usercenter/down-icon.png"></image>
			</view>
			<view class="topstatis">
				<view class="topstatis-item">
					<view class="count">{{clock}}</view>
					<view class="text">工作时间（小时）</view>
				</view>
				<view class="topstatis-item">
					<view class="count">{{money}}</view>
					<view class="text">返佣（元）</view>
				</view>
			</view>
		</view>
		<view class="b-list" v-for="item in list">
			<view class="b-list-item">
				<view class="row01">
					<text class="cell01">{{item.company.merchantName}}</text>
					<text class="cell02">{{item.endtime}}</text>
				</view>
				<view class="row02">
					<text class="cell01">{{item.worktype.workname}}</text>
					<text class="cell02">{{item.clock}}小时</text>
					<text class="cell03">返佣：+{{item.backmoney}}</text>
				</view>
			</view>
			
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			const currentDate = this.getDate({
				format: true
			})
			return {
				title: 'picker',
				array: ['中国', '美国', '巴西', '日本'],
				index: 0,
				date: currentDate,
				time: '12:01',
				money:0,
				clock:0,
				list:[],
				isLastPage:false
				
			}
		},
		computed: {
			startDate() {
				return this.getDate('start');
			},
			endDate() {
				return this.getDate('end');
			}
		},
		onLoad(){
			
			this.myList();
		},
		
		
		onReachBottom() {
			
			console.info("==onReachBottom===="+this.isLastPage);
			if(this.isLastPage) return;
			this.page+= 1;
			this.myList();
			
		},
		methods: {
			
			myList(){
				
				let param = {
					page:1,
					date:this.date
				};
				let that = this;
				this.$api.myworkList(param).then(res => {
				
					if (res.code == 1) {
						that.clock = res.data.clock;
						that.money = res.data.money;
						that.list = res.data.list;
						let length = res.data.list.length;
						for (let i = 0; i < length; i++) {
							that.list.push(res.data.list[i]);
						}
						if (length < 10) {
							that.isLastPage = true;
						} else {
							that.isLastPage = false;
						}
					} 
					console.info(res)
				})
			},
			bindDateChange: function(e) {
				this.date = e.target.value
				this.page = 1;
				this.myList();
			},
			getDate(type) {
				const date = new Date();
				let year = date.getFullYear();
				let month = date.getMonth() + 1;
				let day = date.getDate();

				if (type === 'start') {
					year = year - 60;
				} else if (type === 'end') {
					year = year + 2;
				}
				month = month > 9 ? month : '0' + month;;
				day = day > 9 ? day : '0' + day;
				return `${year}-${month}-${day}`;
			}
		}
	}
</script>

<style lang="scss">
	.topBox {
		position: relative;
		height: 330rpx;

		.topBoxbg {
			width: 100%;
			height: 330rpx;
			position: absolute;
			top: 0;
			left: 0;
			z-index: 0;

			image {
				width: 100%;
				height: 330rpx;
			}
		}

		.timeselect {
			position: relative;
			z-index: 2;
			display: flex;
			padding: 25rpx 0 0 40rpx;

			picker {
				color: #ffffff;
				font-size: 32rpx;
			}

			.select-icon {
				padding-left: 20rpx;
				width: 30rpx;
				height: 30rpx;
			}
		}

		.topstatis {
			position: relative;
			z-index: 2;
			display: flex;
			padding-top: 57rpx;

			.topstatis-item {
				flex: 1;

				.count {
					text-align: center;
					font-size: 48rpx;
					color: #ffffff;
				}

				.text {
					margin-top: 16rpx;
					text-align: center;
					font-size: 28rpx;
					color: #ffffff;
				}
			}
		}
	}

	.b-list {
		.b-list-item {
			margin: 42rpx;
			border-bottom: 1rpx solid #EBEBEB;

			.row01 {
				display: flex;

				.cell01 {
					font-size: 28rpx;
					color: #333333;
					flex: auto;
				}

				.cell02 {
					font-size: 24rpx;
					color: #ADADAD;
				}
			}

			.row02 {
				display: flex;
				margin: 18rpx 0;

				.cell01 {
					font-size: 26rpx;
					color: #666666;
				}

				.cell02 {
					font-size: 26rpx;
					color: #666666;
					margin-left: 65rpx;
					flex: auto;
				}

				.cell03 {
					font-size: 28rpx;
					color: #EC3535;
				}
			}
		}
	}
</style>
